import { createStore } from 'redux';
const defaultState = { isLogin: false };
const reducer = (state = defaultState, action) => {
  console.log("Entered reducer!");
  console.log(action.isLogin);
  if(action.type == "search") {
    let ret = {};
    for (let p in state) {
      ret[p] = state[p];
    }
    if(action.isSearch == true) {
      ret.isSearch = true;
      ret.searchKey = action.searchKey;
      ret.order = "";
    }
    else {
      ret.isSearch = false;
      ret.searchKey = "";
      ret.order = action.order;
    }
    return ret;
  }
  else {
    if (!action.isLogin)
      return {
        order: 'recent',
        isLogin: false,
      }
    else {
      let ret = {};
      for (let p in action) {
        if (p != 'type') {
          ret[p] = action[p];
        }
      }
      console.log("the ret is");
      console.log(ret);
      ret.order = 'recent';
      return ret;
    }
  }
}
const userStore = createStore(reducer);
export default userStore